package net.paoding.rose.jade.statement.jexl;

import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * jexl3 常量
 * @author fusheng.zhang
 * @date 2022-03-08 14:22:30
 */
public class Jexl3Constant {

    /**
     * 常量前缀
     */
    public static String CONST_PREFIX = "_mapConsts";
    /**
     * 参数前缀
     */
    public static String VAR_PREFIX = "_mapVars";
    /**
     *
     */
    public static Pattern MAP_PATTERN = Pattern.compile("\\[([.a-zA-Z0-9_]+)]");
    /**
     * 前缀匹配
     */
    public static Pattern PREFIX_PATTERN = Pattern.compile("([:$@])([a-zA-Z0-9_]+)(\\.[a-zA-Z0-9_]+)*");

    /**
     * 关键字
     */
    public static final String KEYWORD_$ = "$";
    public static final char KEYWORD_$_ = '$';
    public static final String KEYWORD_NAME_SPACE_ = "@";
    public static final String KEYWORD_SHARP = "#";
    public static final String KEYWORD_JOIN = "!";
    public static final String KEYWORD_IF = "if";
    public static final String KEYWORD_ELSE = "#else";
    public static final String KEYWORD_FOR = "for";
    public static final String KEYWORD_NAME_SPACE = "@";

    /**
     * 匹配关键字表达式
     */
    public static final Pattern PATTERN_KEYWORD = Pattern.compile(
            "::" + // 双冒号
                    "|([:$]{1}[a-zA-Z0-9_.]+)" + // :param 或 $param
                    "|\\{([^{}]+)}\\?" + // 可选参数
                    "|#(#|!|if|for|@)?") // #指令
            ;
    /**
     * 匹配 #else 开头
     */
    public static final Pattern PATTERN_ELSE = Pattern.compile("(#else)+");
    /**
     * in(不区分大小写) 匹配
     */
    public static final Pattern PATTERN_IN = Pattern.compile("([a-zA-Z0-9_]*)\\s+in\\s+(.+)", Pattern.CASE_INSENSITIVE);
    /**
     * 匹配命名空间
     */
    public static final Pattern PATTERN_NAME_SPACE = Pattern.compile("([a-zA-Z_][a-zA-Z0-9_]*)\\.([a-zA-Z_][a-zA-Z0-9_]*)");
    /**
     * 命名空间配置
     */
    public static final Map<String, Object> JEXL3_BUILDER_NAME_SPACE = new HashMap<>();

}
